import logging
import os
import traceback

import yaml

logger = logging.getLogger(__name__)

CONFIG_FILE = os.path.join(os.path.dirname(__file__), 'config.yaml')
assert os.path.exists(CONFIG_FILE)


def get_config():
    """返回配置文件对应的字典"""
    cfg_file = CONFIG_FILE

    try:
        with open(cfg_file, 'r', encoding='utf-8') as f:
            cfg = yaml.load(f, Loader=yaml.FullLoader)
        logger.warning(f"日志解析完成：{cfg}")
        return cfg
    except:
        logger.critical("配置文件出错！")
        traceback.print_exc()
        exit()

def data_generator(data_list):
    for item in data_list:
        yield item
